



class BoardPath implements Comparable<BoardPath>
	{
	
		public static enum BeginDirection
		{
			Forward,
			Backwards;
		}
	
		public BoardImplFast board;
		public String path;
		public int depth;
		
		public BeginDirection beginDirection;
		public VisitedEntry lastVisitedEntry;
		
		public int calculatedHeuristic;
		
//		public int[][] boxManhattanDistanceMatrix;
		public DistanceCache distanceCache;
		
//		private static int DEPTH_PER_ITERATION = 3;
		
//		public BoardPath( BoardImplFast board, String path, int depth, BeginDirection beginDirection, 
//				int[][] boxManhattanDistanceMatrix, VisitedEntry lastVisitedEntry, DistanceCache distanceCache )
		public BoardPath( BoardImplFast board, String path, int depth, BeginDirection beginDirection, 
				VisitedEntry lastVisitedEntry, DistanceCache distanceCache )
		{
			this.board = board;
			this.path = path;
			
			this.depth = depth;
			
			this.beginDirection = beginDirection;
			
//			this.boxManhattanDistanceMatrix = boxManhattanDistanceMatrix;
			
			this.lastVisitedEntry = lastVisitedEntry;
			
			this.distanceCache = distanceCache;
			
			calculatedHeuristic = aStarHeuristic();
			
		}
		

		@Override
		public int compareTo(BoardPath arg0) 
		{
//			int refDepth = arg0.getDepthLevel();
//			int selfDepth = this.getDepthLevel();
			
			
				
				int ref = arg0.calculatedHeuristic;
				int self = this.calculatedHeuristic;
				
				if ( self < ref )
				{
					return -1;
				}
				else if ( self > ref )
				{
					return 1;
				}
				else
				{
					return 0;
//					return Integer.parseInt(path);
//					return aStarHeuristic();
				}
				
//			}
		}
		
	
		public int aStarHeuristic()
		{	
			if ( board.isFinished() )
			{
				return Integer.MIN_VALUE;
			}
			
			Cord[] goals = board.getGoals();
			Cord[] boxes = board.getBoxes();
			Cord player = board.getPlayer();
			

			int score = 0;

			

//			score += distanceCache.minimumPlayerDistance(board, player, boxes)^2;
			score += distanceCache.minimumPlayerDistance(board, player, boxes);
			
			for ( Cord box : boxes )
			{

				score += distanceCache.minimumBoxDistance( board, box, goals );
				
			}
			
			
			
//			score += minimumPathFromPlayer;
			
//			System.out.println(score);
			
			return score;
			
//			return 0;
		}
	}